<template>
    <div class="sidebar">
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-submenu :index="item.index+''" :key="item.index" v-if="item.flag==tempflag?true:false">
                        <template slot="title" >
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                        </template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index+''">
                            <i :class="subItem.icon"></i>
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index+''" :key="item.index" v-if="item.flag==tempflag?true:false">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
    export default {
        data() {
            return {
                collapse: false,
                tempflag:JSON.parse(localStorage.getItem("user")).userType,
                items: [
                    {
                        icon: 'iconfont icon-jituanguanli',
                        index: 'firstPage',
                        title: '平台管理员首页',
                        flag:2,
                    },
                    {
                        icon: 'iconfont icon-jituanguanli',
                        index: 'home',
                        title: '门店管理员首页',
                        flag:1,
                    },
                    {
                        icon: 'iconfont icon-jiaozhigongguanli',
                        title: '管理申请管理',
                        flag:2,
                        subs:[
                            {
                                index: 'applyList',
                                title: '门店申请',
                                flag:2,
                                icon: 'iconfont icon-xuexiaoguanli',
                            },
                            {
                                index: 'managePersonList',
                                title: '管理员申请',
                                flag:2,
                                icon: 'iconfont icon-zhiweiguanli-',
                            },
                        ]
                    },
                    {
                        index: 'mendianlist',
                        title: '查看所有门店',
                        icon: 'iconfont icon-classroom',
                        flag:2,
                    },
                    {
                        icon: 'iconfont icon-quanxian',
                        index: 'table',
                        title: '商品管理',
                        flag:1,
                        subs:[
                            {
                                index: 'showgoods',
                                title: '商品列表',
                                flag:1,
                                icon: 'iconfont icon-jiaozhigongguanli',
                            },
                             {
                                index: 'addgoods',
                                title: '新增商品',
                                flag:1,
                                icon: 'iconfont icon-jiaoseguanli',
                            },
                        ]
                    },
                    {
                        index: 'order',
                        title: '订单列表',
                        flag:2,
                        icon: 'iconfont icon-bumenguanli',
                    },
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        },
        // created(){
        //     // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        //     bus.$on('collapse', msg => {
        //         this.collapse = msg;
        //     })
        // }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 200px;
    }
    .sidebar > ul {
        height:100%;
    }
</style>
